package model.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**				
 * BaseDAO		
 *				
 * Version 1.0				
 *				
 * Date: 29-08-2014			
 *				
 * Copyright 				
 *				
 * Modification Logs:				
 * DATE                 AUTHOR          DESCRIPTION				
 * -----------------------------------------------------------------------				
 * 29-08-2014           TriLD            Create					
 */

public class BaseDAO {
	public Connection con = null;
	public PreparedStatement pst = null;
	public ResultSet rs = null;
	public String qry = null;
	// DB Configuration
	public String url = "jdbc:mysql://localhost:3306/mockdb";
	public String id = "root";
	public String pass = "root";

	public BaseDAO() {

	}

	public void openDatabase() {
		try {
			if (con == null || con.isClosed()) {
				Class.forName("com.mysql.jdbc.Driver");
				con = java.sql.DriverManager.getConnection(url, id, pass);
			}
		} catch (ClassNotFoundException cnfex) {
			cnfex.printStackTrace();
		} catch (SQLException se) {
			se.printStackTrace();
		}
	}

	public void closeDatabase() {
		try{
			if(rs != null) {
				rs.close();
			}
			if(pst != null) {
				pst.close();
			}
			if(con != null) {
				con.close();
			}
		} catch (SQLException se) {
			se.printStackTrace();
		}
	}
}

